package com.black.app.service.impl.find;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.black.app.domain.find.AppFindZhangzhishi;
import com.black.app.domain.find.AppFindZhangzhishiTitle;
import com.black.app.domain.req.find.query.AppFIndZhangzhishititlereq;
import com.black.app.domain.resp.find.FindTreeResp;
import com.black.app.mapper.find.AppFindZhangzhishiTitleMapper;
import com.black.app.service.find.AppFindZhangzhishiTitleService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author 30223
* @description 针对表【app_find_zhangzhishi_title(涨知识-文章tabs表)】的数据库操作Service实现
* @createDate 2024-10-25 11:59:26
*/
@Service
public class AppFindZhangzhishiTitleServiceImpl extends ServiceImpl<AppFindZhangzhishiTitleMapper, AppFindZhangzhishiTitle>
    implements AppFindZhangzhishiTitleService {

    @Autowired
    private AppFindZhangzhishiServiceImpl appFindZhangzhishiService;

    @Override
    public List<FindTreeResp> homeFindTree() {
        List<FindTreeResp> findTreeRespList = new ArrayList<>();

        //查询所有标题
        List<AppFindZhangzhishiTitle> appFindZhangzhishiTitleList = this.baseMapper.selectList(null);
        //遍历所有标题
        appFindZhangzhishiTitleList.stream().forEach(item->{
            FindTreeResp findTreeResp = new FindTreeResp();
            findTreeResp.setTypeId(item.getTitleid());
            findTreeResp.setTypeName(item.getTitle());
            buildChildren(findTreeResp);
            findTreeRespList.add(findTreeResp);
        });
        return findTreeRespList;
    }

    @Override
    public PageInfo<AppFindZhangzhishiTitle> paginationQuery(AppFIndZhangzhishititlereq req) {
        return PageHelper.startPage(req.getPageNum(), req.getPageSize()).doSelectPageInfo(() ->{
            this.baseMapper.paginationQuery(req);
        });
    }

    private void buildChildren(FindTreeResp findTreeResp) {
        List<AppFindZhangzhishi> list = this.appFindZhangzhishiService.findByTitleId(findTreeResp.getTypeId());
        findTreeResp.setChildren(list);

    }
}




